'use strict';
module.exports = app => {
  const { STRING, INTEGER, TEXT,DECIMAL } = app.Sequelize;
  const OrderGoods = app.model.define(
      'orderGoods',
      {
          id: {type: INTEGER, primaryKey: true, autoIncrement: true},
          order_no: STRING(255),
          user_id: INTEGER(11),
          status: INTEGER(11),
          order_status: INTEGER(11),
          express_code: STRING(255),
          back_reason: STRING(255),
          express_no: STRING(255),
          express_info: TEXT(),
          express_status: INTEGER(11),
          discounts_price: DECIMAL(10,2),
      },
      {
          tableName: 'order_goods',
          timestamps: true, // 启用时间戳(createdAt, updatedAt)
          updatedAt: 'updated_time', // 不想要 updatedAt
          createdAt: 'create_time', // 想要  createdAt 但是希望名称叫做 created_at
      }
  );
    OrderGoods.associate = function () {
        OrderGoods.hasMany(app.model.OrderGoodsDetail, { foreignKey: 'order_id', targetKey: 'id'})
        OrderGoods.belongsTo(app.model.User, { foreignKey: 'user_id', targetKey: 'id'})
        OrderGoods.belongsTo(app.model.Address, { foreignKey: 'address_id', targetKey: 'id'})
    }
    return OrderGoods
};
